home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * @@@BUILDINFO@@@ 60prefsDialog.jsx 1.0.0.47 07-Feb-2005
- * Copyright 2005 Adobe Systems Incorporated
- * All Rights Reserved.
- *
- * NOTICE: All information contained herein is, and remains the property of
- * Adobe Systems Incorporated and its suppliers, if any. The intellectual
- * and technical concepts contained herein are proprietary to Adobe Systems
- * Incorporated and its suppliers and may be covered by U.S. and Foreign
- * Patents,patents in process,and are protected by trade secret or copyright
- * law. Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained from
- * Adobe Systems Incorporated.
- **************************************************************************/
-
- // Code to create the Preferences dialog
-
- // TODO
- /*
- ? how to handle font names not in the 'prefsFontNames' list?
- Should 'other' bring up a separate font selection dialog?
- */
-
- /////////////////////////////////////////////////////////////////////////
- // Define an 'onSelect' method for the Preferences menu item that will
- // open the Preferences dialog and update the preferences when dismissed.
-
- if (editMenu.preferences)
- editMenu.preferences.onSelect = function()
- {
- /////////////////////////////////////////////////////////////////////////
- // Local variables
-
- var kFontStyleBold = 1;
- var kFontStyleItalic = 2;
- var kFontStyleUnderlined = 4;
-
-
- /////////////////////////////////////////////////////////////////////////
- // The preferences dialog resource
-
- var prefsDlgResSpec =
- "dialog { \
- text:'$$$/ESToolkit/PreferencesDlg/title=Preferences', \
- orientation:'column', \
- selector: DropDownList { \
- alignment:'left', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htSelector=Select the preference options to change' \
- }, \
- panes: Panel { \
- text:'temp', orientation:'stack', margins:[15,20,15,15] \
- } \
- }";
-
- /////////////////////////////////////////////////////////////////////////
- // The text formatting options pane resource
-
- var textFormattingOptsResSpec =
- "group { \
- orientation:'column', alignChildren:'left', visible:false, \
- autoIndent: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/autoindent=I&ndent new lines', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htAutoindent=Indent new lines to same level as previous line' \
- }, \
- lineNums: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/linenumbers=&Display line numbers', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htLinenumbers=Show line numbers to the left of text in an edit pane' \
- }, \
- hilite: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/hilite=&Enable syntax highlighting', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htHilite=Highlight JavaScript reserved words, comments, etc, with different colors', \
- }, \
- tabStops: Group { \
- lbl: StaticText { \
- text:'$$$/ESToolkit/PreferencesDlg/tabstops=Tab stops:' }, \
- list: DropDownList { \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htTabstops=Choose the number of spaces between tab stops' \
- } \
- } \
- }";
-
-
- /////////////////////////////////////////////////////////////////////////
- // The Font options pane resource
-
- var fontOptionsResSpec =
- "group { \
- orientation:'column', alignChildren:'left', visible:false, \
- txtName: Group { \
- lbl: StaticText { \
- text:'$$$/ESToolkit/PreferencesDlg/textFont=Text font:' }, \
- list: DropDownList { \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htTextFont=Choose the font to display text' \
- } \
- }, \
- txtSize: Group { \
- lbl: StaticText { \
- text:'$$$/ESToolkit/PreferencesDlg/textSize=Text size:' }, \
- list: DropDownList { \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htTextSize=Choose the font size to display text' \
- } \
- }, \
- txtStyle: Panel { \
- text:'$$$/ESToolkit/PreferencesDlg/textStyle=Text style', \
- orientation:'row', alignment:'center', \
- bold: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/bold=&Bold', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htBold=Use a bold typeface to display text' \
- }, \
- italic: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/italic=&Italic', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htItalic=Use an italic typeface to display text' \
- } \
- } \
- }";
-
-
- /////////////////////////////////////////////////////////////////////////
- // The "help" options pane resource
-
- var helpOptionsResSpec =
- "group { \
- orientation:'column', alignChildren:'left', visible:false, \
- dynamicHelp: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/dynamichelp=Display JavaScript &variables',\
- helpTip:'$$$/ESToolkit/PreferencesDlg/hiDynamichelp=Show types and values of variables when you rest the mouse cursor over them' }, \
- helpTips: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/helptips=Enable UI &help tips', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htHelptips=Display a help message when you rest the mouse cursor over a control in the user interface' } \
- }";
-
-
- /////////////////////////////////////////////////////////////////////////
- // The general options pane resource
-
- var generalOptionsResSpec =
- "group { \
- orientation:'column', alignChildren:'left', visible:false, \
- language: Group { \
- orientation:'row', \
- lbl: StaticText { \
- text:'$$$/ESToolkit/PreferencesDlg/language=Language:' }, \
- list: DropDownList { \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htLanguage=Select the language to present in the user interface' \
- } \
- }, \
- scripts: Group { \
- orientation:'column', alignChildren:'left', \
- lbl: StaticText { \
- text:'$$$/ESToolkit/PreferencesDlg/scriptsfolder=Scripts folder:' }, \
- folder: Group { \
- path: EditText { \
- preferredSize:[220,20], \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htFolder=Pathname of the folder that contains scripts' \
- }, \
- browse: Button { \
- text:'$$$/ESToolkit/PreferencesDlg/browse=&Browse...', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htFolderBrowse=Use a folder selection dialog to choose the folder that contains scripts' \
- } \
- } \
- }, \
- cleanWorkspace: Checkbox { \
- text:'$$$/ESToolkit/PreferencesDlg/cleanWorkspace=&Start with a clean workspace', \
- helpTip:'$$$/ESToolkit/PreferencesDlg/htCleanWorkspace=On startup, do not open any files from the previous session' \
- } \
- }";
-
-
- /////////////////////////////////////////////////////////////////////////
- // The buttons group resource
-
- var btnsResSpec =
- "group { \
- alignment:'right', \
- okBtn: Button { text:'$$$/CT/ExtendScript/UI/OK=OK', \
- properties:{ name:'ok' } }, \
- cancelBtn: Button { text:'$$$/CT/ExtendScript/UI/Cancel=Cancel', \
- properties:{ name:'cancel' } } \
- }"
-
-
- /////////////////////////////////////////////////////////////////////////
- // Create the dialog
-
- initDialogPrefs();
-
- var prefsDlg = new Window (prefsDlgResSpec);
-
- // Create the text formatting options pane
- prefsDlg.panes.textFormattingOptionsPane = prefsDlg.panes.add (textFormattingOptsResSpec);
- initTextFormattingOptions (prefsDlg.panes.textFormattingOptionsPane);
-
- // Create the font options pane
- prefsDlg.panes.fontOptionsPane = prefsDlg.panes.add (fontOptionsResSpec);
- initFontOptions (prefsDlg.panes.fontOptionsPane);
-
- // Create the help options pane
- prefsDlg.panes.helpOptionsPane = prefsDlg.panes.add (helpOptionsResSpec);
- initHelpOptions (prefsDlg.panes.helpOptionsPane);
-
- // Create the general options pane
- prefsDlg.panes.generalOptionsPane = prefsDlg.panes.add (generalOptionsResSpec);
- initGeneralOptions (prefsDlg.panes.generalOptionsPane);
-
- // Initialize the 'selector' list that chooses which preference pane to show
- var prefsPanes = prefsDlg.panes;
- initSelectorList (
- prefsDlg.selector, prefsPanes,
- [
- "$$$/ESToolkit/PreferencesDlg/textTitle=Text formatting options", prefsPanes.textFormattingOptionsPane,
- "$$$/ESToolkit/PreferencesDlg/fontTitle=Font options", prefsPanes.fontOptionsPane,
- "$$$/ESToolkit/PreferencesDlg/helpTitle=Help options", prefsPanes.helpOptionsPane,
- "$$$/ESToolkit/PreferencesDlg/generalTitle=General options", prefsPanes.generalOptionsPane
- ]);
-
- // Finally, create the OK and Cancel buttons
- prefsDlg.btns = prefsDlg.add (btnsResSpec);
- with (prefsDlg.btns) {
- // Dialog window is 2 levels in hierarchy up from the buttons
- okBtn.onClick = function () { this.parent.parent.close(1); }
- cancelBtn.onClick = function () { this.parent.parent.close(2); }
- }
-
- // When the dialog is shown, re-locate 'pane selector' list to the top of the panes panel
- prefsDlg.onShow = positionSelectorList;
-
- /////////////////////////////////////////////////////////////////////////
- // Configure the dialog, show it, and set any changed preferences
-
- configureDialogFromPrefs (prefsDlg, prefs.preferencesDialogPrefs);
- var ok = prefsDlg.show() == 1;
- updateDialogPrefs (prefsDlg, prefs.preferencesDialogPrefs);
-
- if (ok) {
- setFontOptionPreferences (prefsDlg.panes.fontOptionsPane);
- setTextFormattingPreferences (prefsDlg.panes.textFormattingOptionsPane);
- setHelpPreferences (prefsDlg.panes.helpOptionsPane);
- setGeneralPreferences (prefsDlg.panes.generalOptionsPane);
- }
-
-
- /////////////////////////////////////////////////////////////////////////
- // initFontOptions: initialize the font options pane
-
- function initFontOptions (pane)
- {
- var item, i;
- var fontNames = ["Application", "System", "Monospace", "Serif", "SansSerif"];
- var prefsFontNames = ["*application", "*system", "*monospace", "*serif", "*sansserif"];
- var textSizes = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72];
- with (pane) {
- // Create a list of text font names and select the preferred one
- for (i = 0; i < fontNames.length; i++) {
- item = txtName.list.add ( "item", fontNames[i]);
- item.prefsName = prefsFontNames[i];
- if (item.prefsName == prefs.fontName)
- txtName.list.selection = item;
- }
-
- // Create a list of text font sizes and select the preferred one
- for (i = 0; i < textSizes.length; i++) {
- item = txtSize.list.add ( "item", textSizes[i]);
- if (item.text == prefs.fontSize)
- txtSize.list.selection = item;
- }
-
- // Show the preferred text style
- txtStyle.bold.value = prefs.fontFace & kFontStyleBold;
- txtStyle.italic.value = prefs.fontFace & kFontStyleItalic;
- }
- } // initFontOptions
-
-
- /////////////////////////////////////////////////////////////////////////
- // setFontOptionPreferences: set preferences from the selected font options
- function setFontOptionPreferences (pane)
- {
- with (pane) {
- if (txtName.list.selection != null)
- prefs.fontName = txtName.list.selection.prefsName;
- if (txtSize.list.selection != null)
- prefs.fontSize = txtSize.list.selection.text;
- var newFontFace = 0;
- if (txtStyle.bold.value)
- newFontFace += kFontStyleBold;
- if (txtStyle.italic.value)
- newFontFace += kFontStyleItalic;
- prefs.fontFace = newFontFace;
- }
- } // setFontOptionPreferences
-
-
- /////////////////////////////////////////////////////////////////////////
- // initTextFormattingOptions: initialize the text formatting options pane
-
- function initTextFormattingOptions (pane)
- {
- var i;
- var tabStopSettings = [2, 4, 6, 8, 12, 16];
- with (pane) {
- // Load the current text formatting preferences
- autoIndent.value = prefs.autoIndent;
- // wrap.value = prefs.wrap;
- lineNums.value = prefs.lineNumbers;
- hilite.value = prefs.hilite;
-
- // Load the possible tab stops and select the preferred one
- for (i = 0; i < tabStopSettings.length; i++) {
- item = tabStops.list.add ( "item", tabStopSettings[i]);
- if (item.text == prefs.tabs)
- tabStops.list.selection = item;
- }
- }
- } // initTextFormattingOptions
-
-
- /////////////////////////////////////////////////////////////////////////
- // setTextFormattingPreferences: set preferences from the selected font options
- function setTextFormattingPreferences (pane)
- {
- with (pane) {
- prefs.autoIndent = autoIndent.value == 1;
-
- // prefs.wrap = wrap.value == 1;
-
- prefs.lineNumbers = lineNums.value == 1;
- MenuElement.find('edit/lines').checked = prefs.lineNumbers;
-
- prefs.hilite = hilite.value == 1;
- MenuElement.find('edit/hilite').checked = prefs.hilite;
-
- if (tabStops.list.selection != null)
- prefs.tabs = tabStops.list.selection.text;
- }
- } // setTextFormattingPreferences
-
-
- /////////////////////////////////////////////////////////////////////////
- // initHelpOptions: initialize the help options pane
-
- function initHelpOptions (pane)
- {
- with (pane) {
- // Load the current help preferences
- dynamicHelp.value = prefs.dynamicHelp;
- helpTips.value = prefs.helpTips;
- }
- } // initHelpOptions
-
-
- /////////////////////////////////////////////////////////////////////////
- // setHelpPreferences: set preferences from the selected help options
- function setHelpPreferences (pane)
- {
- with (pane) {
- prefs.dynamicHelp = dynamicHelp.value == 1;
-
- prefs.helpTips = helpTips.value == 1;
- }
- } // setHelpPreferences
-
-
- /////////////////////////////////////////////////////////////////////////
- // initGeneralOptions: initialize the general options pane
-
- function initGeneralOptions (pane)
- {
- /* We determine the list of supported languages by searching the 'required'
- folder for all the .dat files: each one has the translations of all
- strings shown in our UI, and each file begins with an identifying string
- of the form "$$$/ESToolkit/A/Language=English" that tells us what language
- it is for. The name of a .dat file is the locale for the language translations
- it contains. */
- var i, item;
- var languageFiles = app.requiredFolder.getFiles ('*.dat');
- var languages = new Array();
- var key = "$$$/ESToolkit/A/Language=";
- for (i = 0; i < languageFiles.length; i++) {
- if (languageFiles[i].open("r")) {
- var data = languageFiles[i].read();
- var loc = data.indexOf (key);
- if (loc >= 0) {
- loc += key.length;
- var s = data.substring (loc, data.indexOf ('"', loc));
- // Get locale name from the file name
- var locale = ":" + languageFiles[i].name;
- // Strip off the .dat extension and append to language name
- languages.push (s + locale.substring (0, locale.length - 4));
- }
- }
- }
- languages.sort();
-
- with (pane) {
- // Create list of languages, headed by a 'Default' item
- item = language.list.add ("item", "$$$/ESToolkit/PreferencesDlg/defaultLang=Default");
- item.locale = $.locale;
- language.list.add ("separator");
-
- // If there's no prefs file for locale, the 'Default' item is selected
- var localePrefsFile = new File (prefs.createFolder() + "/locale.txt");
- if (localePrefsFile.open ("r"))
- localePrefsFile.close();
- else
- language.list.selection = item;
-
- // Load the language items, noting the 'selected' one if not using the Default (above)
- for (i = 0; i < languages.length; i++) {
- var languageLocale = languages[i].split(":");
- item = language.list.add ("item", languageLocale[0]);
- item.locale = languageLocale[1];
- if (language.list.selection == null && item.locale == prefs.locale)
- language.list.selection = item;
- }
- // Remember which item we marked as the selection, to tell if it changed later
- language.list.initialSelection = language.list.selection.index;
-
- // If only 1 (or no) language choices, disable the language selector
- if (languages.length <= 1)
- language.list.enabled = false;
-
- // Load the current scripts pathname
- var scriptsFolder = Folder (prefs.scripts);
- scripts.folder.path.text = scriptsFolder.fsName;
-
- // Create a "select folder" dialog for the Browse button
- scripts.folder.browse.onClick = function ()
- {
- // Let user select a new scripts folder: show the current one
- var folderEditText = this.parent.path;
- var currentScriptsFolder = Folder(folderEditText.text);
- var selectTitle = localize ("$$$/ESToolkit/PreferencesDlg/selectScripts=Select the scripts folder");
- var newFolder = Folder.selectDialog (selectTitle, currentScriptsFolder);
- if (newFolder != null)
- folderEditText.text = newFolder.fsName;
- }
-
- // Load the current 'start with clean workspace' setting
- cleanWorkspace.value = prefs.cleanWorkspace;
- }
- } // initGeneralOptions
-
-
- /////////////////////////////////////////////////////////////////////////
- // setGeneralPreferences: set preferences from the selected general options
- function setGeneralPreferences (pane)
- {
- with (pane) {
- // Use the specified language if it has changed
- var selectedLanguage = language.list.selection;
- if ((selectedLanguage != null) &&
- (language.list.initialSelection != selectedLanguage.index))
- {
- var updatedOK = false;
- prefs.locale = selectedLanguage.locale;
-
- // Create a path to the 'locale pref' file
- var fld = prefs.createFolder();
- var localePrefFile = new File (fld + "/locale.txt");
-
- // The 'Default' language item is always at list index 0.
- var isDefault = selectedLanguage.index == 0;
- if (isDefault) {
- // If 'Default' was selected, delete the obsolete 'locale pref' file
- updatedOK = localePrefFile.remove();
- }
- else {
- // create or update the locale pref file
- updatedOK = localePrefFile.open ("w");
- if (updatedOK) {
- localePrefFile.writeln (prefs.locale);
- localePrefFile.close();
- }
- }
-
- if (updatedOK)
- messageBox ("$$$/ESToolkit/Language/OK=The new language setting will take effect the next time the program starts.");
- else
- errorBox ("$$$/ESToolkit/Language/Error=Cannot switch to the new language!");
- }
-
- // Use the specified scripts path if it has changed
- var currScriptsFolder = Folder (prefs.scripts);
- if (currScriptsFolder.fsName != scripts.folder.path.text) {
- var newScriptsFolder = Folder (scripts.folder.path.text);
- prefs.scripts = newScriptsFolder.absoluteURI;
- }
-
- // Set the 'start with clean workspace' option
- prefs.cleanWorkspace = cleanWorkspace.value != 0;
- }
- } // setGeneralPreferences
-
-
- /////////////////////////////////////////////////////////////////////////
- /* initSelectorList
- Setup the list to show 1 pane for each list item.
- 'selector' is the DropDownList that will contain names of preference panes.
- 'panes' is the panel that the selector list should be positioned over
- 'selections' is an array of "title, pane" pairs, where 'pane' is the
- pane to make visible when the given 'title' is selected in the list.
- */
- function initSelectorList (selector, panes, selections)
- {
- // Load the list with preference pane titles
- var pair;
- for (pair = 0; pair < selections.length; pair += 2) {
- item = selector.add ("item", localize(selections[pair]));
- item.pane = selections[pair+1];
- }
-
- /* When a list item is selected, hide the currently visible preference pane
- and show the one corresponding to the selected item. */
- selector.onChange = function ()
- {
- var paneToShow = this.selection.pane;
- this.currPane.hide();
- paneToShow.show();
- this.currPane = paneToShow;
- }
- } // initSelectorList
-
-
- /////////////////////////////////////////////////////////////////////////
- // positionSelectorList: an onShow() callback for the prefsDlg window
- function positionSelectorList ()
- {
- // Move the 'selector' list from just above the panes Panel to the top of
- // the panes Panel, indented 15 pixels from the left and straddling the border
- this.selector.location.x = this.panes.location.x + 15;
-
- /* Move the 'panes' and 'btns' panels up to center the 'panes' border under
- the selector list. The calculation first determines how far to move
- to get the panes top at the top of the selector list (which is too far),
- then it backs off by adjusting for the height of the title area in the
- panes panel. We use the height of any StaticText element to get the
- height of the panel title. */
- var crunchSpace = this.spacing + this.selector.size.height;
- crunchSpace -= ((this.selector.size.height - this.panes.generalOptionsPane.language.lbl.size.height) / 2);
- this.panes.location.y -= crunchSpace;
- this.btns.location.y -= crunchSpace;
-
- // Make the dialog correspondingly shorter
- this.size.height -= crunchSpace;
- } // positionSelectorList
-
-
- /////////////////////////////////////////////////////////////////////////
- // initDialogPrefs()
- // Initialize the 'preferenceDialogPrefs' object, creating it if necessary.
- function initDialogPrefs()
- {
- // If necessary, create an initial 'preferencesDialogPrefs' property on the
- // global 'prefs' object, to hold the user preferences for the Preferences dialog
-
- var prefsObj = { allProperties:[ ["dialogLocation", null], ["selectedPane", 0] ] };
- if (typeof prefs.preferencesDialogPrefs == "undefined") {
- // Create initial prefs object and define default property values
- for (var i = 0; i < prefsObj.allProperties.length; i++)
- prefsObj[prefsObj.allProperties[i][0]] = prefsObj.allProperties[i][1];
- prefs.preferencesDialogPrefs = prefsObj;
- }
-
- if (typeof prefs.preferencesDialogPrefs.initDone == "undefined") {
- // Finish 'first-time thru' setup of preferencesDialogPrefs object
- prefs.preferencesDialogPrefs.initDone = true;
- prefs.preferencesDialogPrefs.allProperties = prefsObj.allProperties;
-
- /* Define the toSource() method of the preferencesDialogPrefs object
- to return a string that is executable code which creates the
- preferencesDialogPrefs object at initialization time. */
- prefs.preferencesDialogPrefs.toSource = function()
- {
- /* Iterate thru the preferencesDialog preference properties, appending each
- property name / value pair to the source string we are building */
- var src = "{ ";
- for (var i = 0; i < this.allProperties.length; i++) {
- if (i > 0)
- src += ", ";
- src += strVal (this, this.allProperties[i][0]);
- }
- src += " }";
- return src;
-
- // Utility that returns a string for the named 'prop' / value pair
- function strVal (prefs, prop)
- {
- var str = prop + ": ";
- var value = prefs[prop];
- if (typeof value == 'object')
- str += value.toSource();
- else if (typeof value == "string")
- str += "'" + value.toString() + "'";
- else
- str += value.toString();
- return str;
- }
- }
- }
- } // initDialogPrefs
-
-
- /////////////////////////////////////////////////////////////////////////
- // configureDialogFromPrefs()
- // Initialize dialog settings from the saved 'preferenceDialogPrefs' values.
- // Called on each 'show' of the preferences dialog.
- function configureDialogFromPrefs (dlg, dlgPrefs)
- {
- if (dlgPrefs.dialogLocation != null)
- dlg.location = dlgPrefs.dialogLocation;
- else
- // Location unknown: center over the main window
- dlg.center(window);
-
- // Show the last known preferences pane
- dlg.selector.selection = dlgPrefs.selectedPane;
- dlg.selector.currPane = dlg.selector.selection.pane;
- } // configureDialogFromPrefs
-
-
- /////////////////////////////////////////////////////////////////////////
- // updateDialogPrefs()
- // Update the 'preferenceDialogPrefs' object with current dialog settings.
- function updateDialogPrefs (dlg, dlgPrefs)
- {
- // Remember dialog screen location
- dlgPrefs.dialogLocation = dlg.location;
- // Remember what prefences pane was selected
- dlgPrefs.selectedPane = dlg.selector.selection.index;
- } // updateDialogPrefs
-
- } // end of onSelect function
-